<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //题1
        const arr = ['name', 'age', 'hhh', 'hhh', 'age', 'hhh', 'hhh', 'hhh']
        let obj = {}
        arr.map(item =>obj[item] = (obj[item] + 1) || 1)
        console.log(obj);

        //题2
        const a = [1, 2, 3, 5]
        const b = [1, 3, 5, 6]

        const num = a.filter(item =>b.indexOf(item) == -1)
        console.log(num);

        //题3
        const arr2 = [1, 2, 3, 2, 9]

        //空数组indexOf法......................................

        let arr3 = []
        arr2.map((item, i) => arr3.indexOf(item) == -1 && arr3.push(item))
        console.log(arr3);


        //fiter+indexOf........................................

        /* const arr3= arr2.filter((item,i)=>arr2.indexOf(item,0)===i)
        console.log(arr3); */


        //排序sort法+splice.....................................

        /*arr2.sort().map((item, i) => arr2[i] === arr2[i + 1] && arr2.splice(i + 1, 1))
        console.log(arr2); */


        //for嵌套+splice........................................

        /* for (let i = 0; i < arr2.length; i++) {
            for (let j = i + 1; j < arr2.length; j++) {
                arr2[i] === arr2[j] && arr2.splice(j, 1)
            }
        }
        console.log(arr2); */

        

    </script>
</body>

</html>